package com.corpgovernment.organization.controller;

import com.corpgovernment.api.organization.soa.resident.GetAllDifferentialPriceRequest;
import com.corpgovernment.api.organization.soa.resident.GetDifferentialPriceRequest;
import com.corpgovernment.api.organization.soa.resident.GetDifferentialPriceResponse;
import com.corpgovernment.api.travelstandard.vo.HotelControlVo;
import com.corpgovernment.common.base.BaseUserInfo;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.organization.service.HotelResidentService;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/hotelResident")
public class HotelResidentController {

    @Autowired
    private HotelResidentService hotelResidentService;

    @RequestMapping("/getDifferentialPrice")
    public JSONResult<Map<Integer, GetDifferentialPriceResponse>> getDifferentialPrice (@RequestBody @Valid GetDifferentialPriceRequest request, BaseUserInfo userInfo) {
        Map<Integer, GetDifferentialPriceResponse> responseMap = new HashMap<>();
        List<Map<Integer, List<GetDifferentialPriceRequest.Resident>>> residents = request.getResidentMap();
        if (CollectionUtils.isEmpty(residents)) {
            return JSONResult.success(responseMap);
        }
        for (Map<Integer, List<GetDifferentialPriceRequest.Resident>> residentMap : residents) {
            for (Integer roomNumber : residentMap.keySet()) {
                List<GetDifferentialPriceRequest.Resident> residentList = residentMap.get(roomNumber);
                request.setResidentList(residentList);
                GetDifferentialPriceResponse response = hotelResidentService.getDifferentialPrice(request, userInfo);
                responseMap.put(roomNumber, response);
            }
        }
        return JSONResult.success(responseMap);
    }

    /**
     *  多房间多人   同住差标查询同意收口
     *
     * @param request
     * @return
     */
    @RequestMapping("/getAllDifferentialPrice")
    public JSONResult<HotelControlVo> getAllDifferentialPrice (@RequestBody GetAllDifferentialPriceRequest request) {
        return JSONResult.success(hotelResidentService.getAllDifferentialPrice(request, request.getUserInfo()));
    }
}
